<?php
$version = Zend_Registry::get('version');  
$front_template = Zend_Registry::get('front_template');

if($this->groupInfo['meta_keywords']){ $this->headMeta()->setName('keywords',$this->groupInfo['meta_keywords']); }	
if($this->groupInfo['meta_desc']){ $this->headMeta()->setName('description',$this->groupInfo['meta_desc']); }
if($this->groupInfo['news_name']){ $this->headTitle()->headTitle($this->groupInfo['news_name'],'SET')->setSeparator(' - ')->headTitle($this->groupInfo['meta_title']); }


$this->feedbackForm->setEditor($this->serverUrl().$this->baseUrl());
$this->feedbackForm->getEditor();

function feedback_truncate($phrase,$start_words, $max_words)
{
   $phrase_array = explode(' ',$phrase);
   if(count($phrase_array) > $max_words && $max_words > 0)
      $phrase = implode(' ',array_slice($phrase_array, $start_words, $max_words)).'...';  
   return $phrase;
}

$allow_obj = new News_View_Helper_Allow();
if (!$allow_obj->allowRule('list',null,null,$this->group_datas['role_id'])) : ?>
<div class="grid_12 t_a_bottom">
		<?php echo $this->translator->translator('Member_Access_deny_desc'); ?>
	</div>
<?php else : 


$format_arr = explode(',',$this->group_datas['img_type']);
for($i = 0; $i < count($format_arr); $i++)
{
	$format_arr[$i] = '*.'.$format_arr[$i];
}
$file_format = implode(';',$format_arr);
?>

<script type="text/javascript">

$(document).ready(function() {	

	function openMsgDialog(msg)
	{
		$('#dialog_msg').html(msg).dialog({
			autoOpen: true,
			modal: true,
			show: 'explode',
			resizable: true,				
			buttons: [{ text: "<?php echo html_entity_decode($this->translator->translator('common_ok'), ENT_QUOTES, 'UTF-8'); ?>", click: function() { $(this).dialog('option', 'hide', 'explode').dialog("close"); } } ],
			open: function(event, ui)
				 {
					setTimeout(function() 
					{									
						if($('#' + event.target.id).dialog('isOpen'))
						{
							$('#' + event.target.id).dialog('option', 'hide', 'explode').dialog('close');										
						}
					}, 10000);
				  }
		});
	}
	
	$('a.reset_feedback_btn').click(function() {				
		 resetFeedbackFields();
		 removeError();	
		 imageThumbnil();	
	});
	
	function resetFeedbackFields()
	{
		$( "#formFeedback" )[ 0 ].reset();
		$('#selected_file_page_thumb').html('');
		$('#page_thumb').val('');
	}
	
	function removeError()
	{
		$('#actionMessage').html('');
		
		var filename = '';
		var filevalue = '';		
		$.each($('#formFeedback').serializeArray(), function(i, field) {	
		  if(field.name.match(/\[\]$/))
		  {
			  var filearr = field.name.split('[]');
			  filename = filearr[0];					
		  }
		  else
		  {
			  filename 	= 	field.name;
		  } 			
		  $('#'+filename).removeClass('ui-state-error');
		  $('#'+filename+'_err').html('');									
		});				
	}
	
	function addError(key,errMsg)
	{
		var err_id = key+'_err';
		var field_name = key;
		$('#'+field_name).addClass('ui-state-error');
		$('#'+err_id).append(errMsg);
	}
	
	function openLoaderDialog()
	{
		$('#dialog_container').dialog({
					autoOpen: true,
					modal: true,
					show: 'explode',
					resizable: false,				
					open: function(event, ui)
						 {
						 	$("#progressbar").progressbar({
								value:100
				
							});							
						  }
				});
	}
	
	function closeLoaderDialog()
	{
		$('#dialog_container').dialog('option','hide','explode').dialog('close');
	}
	
	function getFeedbackFormData()
	{
		var fieldObj = {};
		var filename = '';
		var filevalue = '';
		$.each($('#formFeedback').serializeArray(), function(i, field) {	
			if(field.name.match(/\[\]$/))
			{
				var filearr = field.name.split('[]');
				filename = filearr[0];
				filevalue = $('#'+filename).val();
				if($('input[name="'+filename+'[]"]').is(':checkbox'))
				{
					var val_arr = [];
					$('input[name="'+filename+'[]"]:checkbox:checked').each(function(i){
					 val_arr[i] = $(this).val();
					});
					filevalue = (val_arr[0] != null) ? val_arr.join(',') : null;					
				}
			}
			else
			{
				filename 	= 	field.name;
				filevalue 	= 	field.value;
			}			
			fieldObj[filename] = (tinyMCE.get(filename)) ? tinyMCE.get(filename).getContent() : filevalue;			
		});
		return fieldObj;
	}
	
	$('a.feedback_btn').click(function() {			
			
			var formData = getFeedbackFormData();	
			formData.group_id	=		'<?php echo $this->group_datas['id'] ; ?>';
		$.ajax({
				url: "<?php echo $this->url( array('module' => 'News','controller' => 'feedback', 'action'     => 'send','menu_id' => $this->escape($this->menu_id) ), 'adminrout',    false) ?>",
			  	type: 'POST',
			  	data: formData,
				beforeSend: function(){						
						removeError();
						openLoaderDialog();				
					 },
				success: function(response){
					//alert(response);					
					var json_arr = eval("("+response+")");										
					if(json_arr.status == 'ok')
					{
						$('#actionMessage').html(succMsgDesign(json_arr.msg));	
						resetFeedbackFields();																
					}
					else if(json_arr.status == 'errV')
					{
						$('#actionMessage').html(errMsgDesign("<?php echo $this->translator->translator('common_err'); ?>"));
												
						for(var i= 0; i < json_arr.msg.length; i++)
						{
							addError(json_arr.msg[i].key,json_arr.msg[i].value);							
						}
					}
					else
					{
						$('#actionMessage').html(errMsgDesign(json_arr.msg));
					}
					closeLoaderDialog();
				},
				error: function(xhr, status, error){
					closeLoaderDialog();
					var msg = "Error! " + xhr.status + " " + error;
					$('#actionMessage').html(errMsgDesign(msg));
				}
		});
	});
	
});

/***********************************************************************UPLOAD FUNCTIONS START********************************************************/

function languageArray()
{
	var language_array = [];
	language_array['portfolio_upload_dy_text_select'] 					= "<?php echo html_entity_decode($this->translator->translator("portfolio_upload_dy_text_select", '', 'Portfolio'), ENT_QUOTES, 'UTF-8'); ?>";
	language_array['portfolio_upload_text_cancel'] 						= "<?php echo html_entity_decode($this->translator->translator("portfolio_upload_text_cancel", '', 'Portfolio'), ENT_QUOTES, 'UTF-8'); ?>";
	language_array['portfolio_upload_text_dropFilesHere'] 				= "<?php echo html_entity_decode($this->translator->translator("portfolio_upload_text_dropFilesHere", '', 'Portfolio'), ENT_QUOTES, 'UTF-8'); ?>";
	language_array['portfolio_upload_text_remove'] 						= "<?php echo html_entity_decode($this->translator->translator("portfolio_upload_text_remove", '', 'Portfolio'), ENT_QUOTES, 'UTF-8'); ?>";
	language_array['portfolio_upload_text_retry'] 						= "<?php echo html_entity_decode($this->translator->translator("portfolio_upload_text_retry", '', 'Portfolio'), ENT_QUOTES, 'UTF-8'); ?>";
	language_array['portfolio_upload_text_statusFailed'] 				= "<?php echo html_entity_decode($this->translator->translator("portfolio_upload_text_statusFailed", '', 'Portfolio'), ENT_QUOTES, 'UTF-8'); ?>";
	language_array['portfolio_upload_text_statusUploaded'] 				= "<?php echo html_entity_decode($this->translator->translator("portfolio_upload_text_statusUploaded", '', 'Portfolio'), ENT_QUOTES, 'UTF-8'); ?>";
	language_array['portfolio_upload_text_statusUploading'] 			= "<?php echo html_entity_decode($this->translator->translator("portfolio_upload_text_statusUploading", '', 'Portfolio'), ENT_QUOTES, 'UTF-8'); ?>";
	language_array['portfolio_upload_text_uploadSelectedFiles'] 		= "<?php echo html_entity_decode($this->translator->translator("portfolio_upload_text_uploadSelectedFiles", '', 'Portfolio'), ENT_QUOTES, 'UTF-8'); ?>";
	language_array['portfolio_file_extension_dy_support'] 				= "<?php echo $this->translator->translator("portfolio_file_extension_dy_support", '', 'Portfolio'); ?>";
	language_array['portfolio_file_extension_dy_not_supportable_ext1'] 	= "<?php echo $this->translator->translator("portfolio_file_extension_dy_not_supportable_ext1", '', 'Portfolio'); ?>";
	language_array['portfolio_file_extension_dy_not_supportable_ext2']  = "<?php echo $this->translator->translator("portfolio_file_extension_dy_not_supportable_ext2", '', 'Portfolio'); ?>";
	language_array['portfolio_file_size_dy_support'] 					= "<?php echo $this->translator->translator("portfolio_file_size_dy_support", '', 'Portfolio'); ?>";
	language_array['portfolio_file_upload_err'] 						= "<?php echo $this->translator->translator("portfolio_file_upload_err", '', 'Portfolio'); ?>";
	return language_array;
}


function successFileDecoretion(fileObj, serverData, upload_field, upload_value_field)
{
		var extension = fileObj.extension;
		var ext = extension.replace('.','');	
		
		var img_path = '';
		switch(ext)
		{
			case 'flv':
			case 'swf':
			case 'FLV':
			case 'SWF':
				img_path = '<?php echo $this->baseUrl(); ?>'+'/application/modules/Administrator/layouts/scripts/images/common/flash.png';
				break;
			case 'mp3':
			case 'MP3':
				img_path = '<?php echo $this->baseUrl(); ?>'+'/application/modules/Administrator/layouts/scripts/images/common/mp3.png';
				break;
			case 'avi':
			case 'wmv':
			case 'wma':
			case 'WMA':
			case 'AVI':
			case 'WMV':
				img_path = '<?php echo $this->baseUrl(); ?>'+'/application/modules/Administrator/layouts/scripts/images/common/avi_thumb.png';
				break;
			case 'pdf':
			case 'doc':
			case 'docx':
			case 'xls':
			case 'xlsx':
			case 'ppt':
			case 'pptx':
			case 'PDF':
			case 'DOC':
			case 'DOCX':
			case 'XLS':
			case 'XLSX':
			case 'PPT':
			case 'PPTX':
				img_path = '<?php echo $this->baseUrl(); ?>'+'/application/modules/Administrator/layouts/scripts/images/common/extImages/'+ext+'.png';
				break;
			default:
				if(isImage(fileObj))
				{				
					img_path = "<?php echo $this->baseUrl().'/'; ?>"+serverData.file_path+'/'+fileObj.name; 
				}
				else
				{	
					img_path = "<?php echo $this->baseUrl().'/'; ?>application/modules/Administrator/layouts/scripts/images/common/all_file_thumb.png";
				}	
				break;
		}		
		
		
		var img_code =  '<span class="thumb"><img src="'+img_path+'" title="'+fileObj.name+'" width="20" height="10" /></span>'
		var down_link = (!isImage(fileObj)) ? '<br /><a href="'+serverData.file_path+'/'+fileObj.name+'"><?php echo $this->translator->translator("common_download", "", "Projects"); ?></a>' : '';
		var checked = '';
		var primary = '&nbsp;&nbsp;&nbsp;';	
		var block = 'selected_file_'+upload_value_field;
		var img_type = '';			
		switch(upload_value_field)
		{
			case 'product_thumb':	
					checked = ($('#'+upload_value_field).val() == '') ? ' checked="checked" ' : '';	
					img_type = 	($('#'+upload_value_field).val() == '') ? "<span class='main'><?php echo $this->translator->translator('gallery_img_main', '', 'Gallery'); ?></span><br />" : "<span class='related'><?php echo $this->translator->translator('gallery_img_related', '', 'Gallery'); ?></span><br />";				
					primary = '<input class="radio_style" type="radio" name="product_thumb_primary" id="product_thumb_primary" '+checked+' value="'+fileObj.name+'" title="<?php echo $this->translator->translator("gallery_primary", '', 'Gallery'); ?>" />';
				break;
			case 'product_file':
					checked = ($('#'+upload_value_field).val() == '') ? ' checked="checked" ' : '';		
					img_type = 	($('#'+upload_value_field).val() == '') ? "<span class='main'><?php echo $this->translator->translator('gallery_img_main', '', 'Gallery'); ?></span><br />" : "<span class='related'><?php echo $this->translator->translator('gallery_img_related', '', 'Gallery'); ?></span><br />";		
					primary = '<input class="radio_style" type="radio" name="product_file_primary" id="product_file_primary" '+checked+' value="'+fileObj.name+'" title="<?php echo $this->translator->translator("gallery_primary", '', 'Gallery'); ?>" />';
				break;
		}
		
		var del_link = '<a href="javascript:void(0)" class="delete_uploaded_image_link" field_name="'+upload_value_field+'" file_name="'+fileObj.name+'" file_path="'+serverData.file_path+'"><?php echo $this->translator->translator("common_delete_title"); ?></a>'+primary+down_link;
				
		if(serverData.multi)
		{		
			$('#'+block).append('<div class="upload-img box">'+img_type+'<span>'+img_code+'<br />&nbsp;'+del_link+'</span></div>');				 
			var file_val = ($('#'+upload_value_field).val() == '') ? fileObj.name :  $('#'+upload_value_field).val()+','+fileObj.name;
		}
		else
		{
			$('#'+block).html('<div class="upload-img box">'+img_type+'<span>'+img_code+'<br />&nbsp;'+del_link+'</span></div>');				 
			var file_val = fileObj.name;	
		}		
		$('#'+upload_value_field).val(file_val);
		deleteFiles("<?php echo $this->translator->translator('gallery_img_main', '', 'Gallery'); ?>", "<?php echo $this->translator->translator('gallery_img_related', '', 'Gallery'); ?>", "<?php echo $this->url( array('module' => 'Portfolio','controller' => 'frontend', 'action'     => 'remove' ), 'adminrout',    true) ?>", "<?php echo $this->translator->translator('common_delete_title'); ?>");	
		imageThumbnil();	
}

function onComplete(e) {
			
}

function onCancel(e) {
	
}

function onProgress(e) {
					
}

/***********************************************************************UPLOAD FUNCTIONS END********************************************************/

/************************************************IMAGE THUMBNIL START************************************************/
function imageThumbnil()
{	
	$("span.thumb").hover(function() {
		$(this).css({'z-index' : '10'}); /*Add a higher z-index value so this image stays on top*/ 
		$(this).find('img').addClass("hover").stop() /* Add class of "hover", then stop animation queue buildup*/
			.animate({
				marginTop: '-110px', /* The next 4 lines will vertically align this image */ 
				marginLeft: '-110px',
				top: '50%',
				left: '50%',
				width: '174px', /* Set new width */
				height: '174px', /* Set new height */
				padding: '20px'
			}, 200); /* this value of "200" is the speed of how fast/slow this hover animates */
	
		} , function() {
		$(this).css({'z-index' : '0'}); /* Set z-index back to 0 */
		$(this).find('img').removeClass("hover").stop()  /* Remove the "hover" class , then stop animation queue buildup*/
			.animate({
				marginTop: '0', /* Set alignment back to default */
				marginLeft: '0',
				top: '0',
				left: '0',
				width: '30px', /* Set width back to default */
				height: '20px', /* Set height back to default */
				padding: '5px'
			}, 400);
	});
}
/************************************************IMAGE THUMBNIL END************************************************/
</script>

<div class="mod">
	<div class="feedback-icon">
        <h1><?php echo $this->escape($this->groupInfo['news_name']); ?></h1>
    </div>

	<div class="clear">&nbsp;</div>

	<?php				
		foreach($this->feedback_list as $entry)
		{
	?>
	<div class="mod-container">    	
        <?php
			if(empty($entry['page_thumb']))
			{
				$img_path = 'application/layouts/scripts/'.$front_template['theme_folder'].'/images/mod_img/avatar.png';
			}
			else
			{
				$img_path = 'data/frontImages/news/page_thumb/'.$this->escape($entry['page_thumb']);
			}
		?>
        <img src="<?php echo $img_path; ?>" <?php if(!empty($this->groupInfo['news_thumb_width'])){ echo 'width="'.$this->escape($this->groupInfo['news_thumb_width']).'"'; } ?> <?php if(!empty($this->groupInfo['news_thumb_height'])){ echo 'height="'.$this->escape($this->groupInfo['news_thumb_height']).'"'; } ?> border="0" class="thumb" />
        <span class="mod-title"><a title="<?php echo $this->escape($entry['page_title']); ?>" href="javascript: void(0);"><?php echo $this->escape($entry['page_name']); ?></a></span>
        <span class="date"><?php echo $this->translator->translator('common_posted_date_title'); ?> <?php echo $this->numbers($this->escape($entry['page_date'])); ?></span><br />
        <?php $desc = $this->escape(strip_tags($entry['page_desc']));
		echo feedback_truncate($desc,0,$this->groupInfo['news_desc_truncate']); ?>
    </div>
    <?php
		}
	?>
    
    <div class="clear">
		<?php echo $this->paginationControl($this->feedback_list, 'Sliding', 'feedback/pagination-flickr.phtml'); ?>
	</div>

	<div class="clear">&nbsp;</div>

	<div class="send-feedback-icon">
    	<h1><?php echo $this->translator->translator('news_frontend_feedback_form'); ?></h1>
	</div>
    
    <div class="clear">&nbsp;</div>

    <form name="formFeedback" id="formFeedback" method="post" enctype="multipart/form-data">
    	<fieldset>
        <legend><?php echo $this->translator->translator('news_frontend_feedback_fieldset'); ?></legend>
        <div id="actionMessage">&nbsp;</div>
        
        <div class="form-label-container">                           	
            <span class="label_class"><?php echo $this->feedbackForm->page_name->getLabel(); if($this->feedbackForm->page_name->isRequired()){ ?><span class="star_class">*</span><?php } ?></span>
        </div>
        
        <div class="form-field-container">
            <span class="ui-widget"><?php echo $this->feedbackForm->page_name; ?></span><br />
            <span class="input-errors" id="page_name_err"></span>	
        </div>
        
        <div class="clear">&nbsp;</div>
        
        <div class="form-label-container clear">                           	
            <span class="label_class"><?php echo $this->feedbackForm->page_thumb->getLabel(); if($this->feedbackForm->page_thumb->isRequired()){ ?><span class="star_class">*</span><?php } ?></span>
        </div>
        
        <div class="form-field-container">
        	<script type="text/javascript">
			  $(function(){
				  /**************************FILE UPLOAD START******************************/																					
				  dynamicUploader("page_thumb_upload", "page_thumb", <?php echo $this->settings_json_info; ?>, languageArray(), "<?php echo $this->url( array('module' => 'Portfolio','controller' => 'frontend', 'action'     => 'upload'), 'adminrout',    true) ?>", "<?php echo $this->url( array('module' => 'Portfolio','controller' => 'frontend', 'action'     => 'remove'), 'adminrout',    true) ?>", false);
				  /**************************FILE UPLOAD END*********************************/
			  });
			 </script>
            <span class="left-float"><?php  echo $this->feedbackForm->page_thumb_upload; ?></span><span id="selected_file_page_thumb"></span>
            <?php echo $this->feedbackForm->page_thumb; ?><br />
            <span class="input-errors" id="page_thumb_err"></span>
        </div>
        
        <div class="form-label-container clear">                           	
            <span class="label_class"><?php echo $this->feedbackForm->page_desc->getLabel(); if($this->feedbackForm->page_desc->isRequired()){ ?><span class="star_class">*</span><?php } ?></span>
        </div>
        
        <div class="form-field-container">
            <span><?php echo $this->feedbackForm->page_desc; ?></span><br />
            <span class="input-errors" id="page_desc_err"></span>
        </div>
        </fieldset>
        
        <div class="clear btn-container">
            <span class="form-button ui-widget-content-1"><a href="javascript:  void(0);" class="reset_feedback_btn"><?php echo $this->translator->translator('common_reset'); ?></a></span>
            <span class="form-button ui-widget-content-1"><a href="javascript:  void(0);" class="feedback_btn"><?php echo $this->translator->translator('common_submit'); ?></a></span>
        </div>
    </form>
</div>
			  
<div id="dialog_msg" title="Message......"></div>
<div id="dialog_container" style="display:none" title="Please Wait For Processing...">
	<div id="progressbar"></div>
</div>
<?php endif; ?>